<?
    include 'include/funcoes.php';
    $erro = array();
	
	$menu = array("perfil");
    
    $id_usuario = $_SESSION['usuario']['id'];
    
    if($_POST){
	
		$SQL = "SELECT senha FROM usuario WHERE id = $id_usuario";
		$result = mysql_query($SQL);	
		$senha = mysql_fetch_array($result);
		$senha = $senha['senha'];
		
		extract($_POST);
		
		if($senhaAtual != $senha)
			$erro['senhaAtual'] = "A senha atual está errada.";

		if($senhaNovaRepetir != $senhaNova)
			$erro['senhaNovaRepetir'] = "As senhas não conferem.";
		
		if(empty($senha) || empty($senhaNovaRepetir) || empty($senhaNova))
			$erro['senhaNova'] = "Não pode haver senha vazia.";
		
		if(count($erro) == 0)
			mysql_query ("UPDATE usuario SET senha = '$senhaNova' WHERE id = $id_usuario ");
    }


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	
	<title><?=PROJECT_NAME?></title>
	
	<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="include/css/milkbox/milkbox.css" media="screen" />	
	<link href="include/css/geral.css" rel="stylesheet" type="text/css" />	
	
	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
	<script type="text/javascript" src="include/js/mootools-core-1.4.3-full-compat-yc.js"> </script>
	<script type="text/javascript" src="include/js/mootools-more-1.4.0.1.js"> </script>	
	<script src="include/js/milkbox-yc.js"></script>

	<script type="text/javascript">
	    var numeroDeFotos = 1;
	    var multiple = false;
	</script>
    </head>
    <body class="interna">	 
	<?
	    $semIrPara = true;
	    require_once 'include/layoutUp.php';
	?>
	
	<h2>Alterar Senha</h2>
	
	<?
		if(count($erro) == 0 && $_POST){
			?>
				<div class="msgsucesso">Senha alterada com sucesso.</div>
			<?
		}
	?>
	
	<form action="" method="post" >
	    <label>Senha atual:</label>
	    <input name="senhaAtual" type="password" class="normal borda1"/>
	    <br />
	    <? echoErro($erro['senhaAtual']); ?>
	    
	    <label>Nova senha:</label>
	    <input name="senhaNova" type="password" class="normal borda1"/>
	    <br />
	    <? echoErro($erro['senhaNova']); ?>
	    
	    <label>Repetir nova senha:</label>
	    <input name="senhaNovaRepetir" type="password" class="normal borda1"/>
	    <br />
	    <? echoErro($erro['senhaNovaRepetir']); ?>
	    <br />
	    <input type="submit" value="Alterar" class="normal borda1"/>
	</form>
    </body>
</html>
